package com.java.net;

import java.io.IOException;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.nio.charset.StandardCharsets;
import java.util.Timer;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class Tomact {
   private static int corePoolSize=8;
   private static BlockingQueue<Runnable>blockingQueue=
           new ArrayBlockingQueue<>(100);
   private static int maximumPoolSize=256;
   private static long keepAliveTime=60;
   private static TimeUnit unit=TimeUnit.SECONDS;
   private static ThreadPoolExecutor poolExecutor=
           new ThreadPoolExecutor(corePoolSize, maximumPoolSize
           , keepAliveTime, unit, blockingQueue);
   public static void main(String[] args)throws IOException{
       ServerSocket server=new ServerSocket(9999);
       System.out.println("server start......");
       while (true){
           Socket clinet=server.accept();
           poolExecutor.execute(new Runnable() {
               @Override
               public void run() {
                        try {
                            OutputStream out=clinet.getOutputStream();
                            String data="HTTP/1.1 200 OK \n\r" +
                              "Content-Typre: text/html;charset=utf-8 \n\r" +
                                    "\n\r" +
                                    "Hello Client Browser";
                            out.write(data.getBytes());
                            out.flush();
                            clinet.close();
                        }catch (Exception e){e.printStackTrace();}
               }
           });
       }
   }
}
